package com.vic.commons.dao;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.github.abel533.sql.SqlMapper;

public abstract class BaseDao<T> extends SqlSessionDaoSupport{
	@Autowired
    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
        super.setSqlSessionFactory(sqlSessionFactory);
    }
	
	private Class<T> entityClass;
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public BaseDao()
	{
		Type genType = getClass().getGenericSuperclass();
		Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
		entityClass = (Class) params[0];
	}
	
    
	public List<Map<String, Object>> findBySql(String sql){
		
		SqlSession sqlSession = super.getSqlSession();//获取sqlSession
		//创建sqlMapper
		SqlMapper sqlMapper = new SqlMapper(sqlSession);
		//查询，返回指定的实体类
		return sqlMapper.selectList(sql);

	}

}
